﻿//+--------------------------------------------------------------------------------------------------
//     
//Description: View Definition Model
//Author: Aravind Ramarathinam (aravr@microsoft.com)
//Copyright © Microsoft Corporation
//Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
//You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
//THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 
//INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 
//See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
// 
//--------------------------------------------------------------------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Runtime.Serialization;

namespace VmroleAuthor.Models
{
    [DataContract]
    public class ViewDefinition
    {
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string Version { get; set; }
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string Label { get; set; }
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string PublisherLabel { get; set; }
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string Description { get; set; }
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string DefaultLanguageCode { get; set; }
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public List<ViewDefSection> Sections { get; set; }
     
    }

    [DataContract]
    public class ViewDefSection
    {
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string Title { get; set; }
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public List<ViewDefCategory> Categories { get; set; }
    }

    [DataContract]
    public class ViewDefCategory
    {
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string CategoryName { get; set; }
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public List<ViewDefParameter> Parameters { get; set; }
    }

    public enum ViewDefParameterType
    {
        String,
        Number,
        ComputerNamePattern,
        Boolean,
        Option,
        Credential,
        VMSize,
        OSVirtualHardDisk,
        DataVirtualHardDisk,
        Network,
        OSTimeZone,
        SecureString,
        MultiLineString
    }

    /// <summary>
    /// Requires custom serialization/deserialization
    /// </summary>
    [DataContract]  
    public class OptionValue
    {
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string Key { get; set; }
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string Value { get; set; }
    }

    [DataContract]  
    public class ViewDefParameter
    {        
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string Type
        {
            get;
            set;          
        }
       
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string Name { get; set; } 
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string Label { get; set; }
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string DefaultValue { get; set; }
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string Description { get; set; }
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public bool Configurable { get; set; }

        /// <summary>
        /// Used only if it is OSVirtualHardDiskParameterType
        /// </summary>
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public List<string> ImageTags { get; set; }
     
        /// <summary>
        /// Requires custom serialization/deserialization
        /// </summary>
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public List<OptionValue> OptionValues { get; set; }
        
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public ViewDefParameterValidation Validation { get; set; }   
    }
  

    [DataContract]
    public class ViewDefParameterValidation
    {
        // Required for all param types
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public bool Required { get; set; }  // of type

        //Optional for StringParam
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public int? MinLength{ get; set; }

        //Optional for StringParam
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public int? MaxLength { get; set; }

        //Optional for StringParam
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string RegExp { get; set; }

        //Optional for NumParam
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public int? MinRange { get; set; }

        //Optional for NumParam
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public int? MaxRange { get; set; }         
       
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public ViewDefParameterValidationMessages Messages { get; set; }

    }


    [DataContract]
    public class ViewDefParameterValidationMessages
    {
        //Required For all ParamTypes
        [DataMember(IsRequired = true, EmitDefaultValue = false)]
        public string Required { get; set; }

        //Optional for StringParam. E.g., Computer Name can be of 10 to 60 characters
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string Length { get; set; }

        //Optional for StringParam. E.g., Computer Name is not valid
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string RegExp { get; set; }

        //Optional for NumberParam. E.g., Instance count should be between 1 and 100
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string Range { get; set; }
    }

}
